package com.hx.dc.controllor;

import com.hx.dc.entity.SysParam;
import com.hx.dc.service.SysParamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.PostConstruct;
import java.util.Map;

/**
 * Created by death on 2019/2/18.
 */
@Controller
@RequestMapping("sysParam")
public class SysParamAction extends BaseAction {

    @Autowired
    private SysParamService sysParamService;


    @RequestMapping(value = "/selectPage")
    @ResponseBody
    // easyui提交数据：page:1 rows:15
    public Object selectPage(SysParam sysParam, Integer page, Integer rows) {
        System.out.println("page:" + page + ",rows:" + rows);
        return this.getPage(sysParamService.selectPage(sysParam, page, rows));
    }


    @RequestMapping(value = "/reLoadSysParam")

    public Object reLoadSysParam(SysParam sysParam) {
        loadSysParam(sysParam);
        return null;
    }

    @PostConstruct
    private void initSysParam() {
        loadSysParam(null);
    }

    private void loadSysParam(SysParam sysParam) {
        Map<String, Map<Integer, String>> sysParamMap = sysParamService.loadSysParam(null);
        application.setAttribute("sysParamMap", sysParamMap);
        System.out.println("-----------------系统参数加载完毕！----------------");
    }

}